# _*_ coding : utf-8 _*_
# @Time : 2022/1/18 20:54
# @Author : StephenQukry
# @File : urllib_test07post请求
# @Project : Test2
import  urllib.request
import  urllib.parse
url = 'https://fanyi.baidu.com/sug'
headers = {'User-Agent':
               'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0'}

data = {
    'kw':'spider'
}

data = urllib.parse.urlencode(data).encode('utf-8')
#post请求的参数 必须要进行编码


request = urllib.request.Request(url = url,data = data,headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode('utf-8')

import json
obj = json.loads(content)
print(obj)
